package me.zhengjie.pm.projectdepartment.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.org.departmentbase.domain.DepartmentBase;
import me.zhengjie.pm.projectbase.domain.ProjectBase;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;

/**
* @author ZGZ
* @date 2020-04-14
*/
@Entity
@Data
@Table(name="project_department")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ProjectDepartment implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 项目 */
    @Column(name = "project_id")
    private Integer projectId;
    @OneToOne
    @JoinColumn(name = "project_id", insertable = false, updatable = false)
    private ProjectBase projectBase;

    /** 部门 */
    @Column(name = "department_id")
    private Integer departmentId;
    @OneToOne
    @JoinColumn(name = "department_id", insertable = false, updatable = false)
    private DepartmentBase departmentBase;

    /** 部门承担责任 */
    @Column(name = "type")
    private String type;

    /** 描述 */
    @Column(name = "`describe`")
    private String describe;

    public void copy(ProjectDepartment source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}